<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class SdAnnounce extends CI_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->library('HttpPost');
		$this->load->model('Court_Model');
		$this->load->helper('url_helper');
	}
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 *        http://example.com/index.php/welcome
	 *    - or -
	 *        http://example.com/index.php/welcome/index
	 *    - or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */


	public function sdlist()
	{
		$data=array();
		$data['pageno'] = '';
		$data['pagesize'] = 15;
		$data['cbfy'] = '';
		if($this->input->post('pageno')==""){
			$data['pageno'] = 1;
		}else{
			$data['pageno'] = $this->input->post('pageno');
		}
		$data['cbfy'] = $this->input->post('cbfy');
		if(empty($data['cbfy'])){
			$data['cbfy']='1304';
		}
		if($this->input->post('pagesize')==""){
			$data['pagesize'] = 15;
		}else{
			$data['pagesize'] = $this->input->post('pagesize');
		}
		$url='http://www.zjsfgkw.cn/Notice/NoticeSD';
		$timeout = 40;
		$response=$this->httppost->post($url,$data,$timeout);
		$sdlist=json_decode($response);

	//	print_r($sdlist->list);
		$courts=array();
		if (!($this->input->post("isAjax"))) {
			$courts=$this->Court_Model-> get_all_courts();
		}
		$articles=array('title'=>'送达公告');
		$articles['sd_announces']=$sdlist;
		$articles['query_fy']=$data['cbfy'];
		$articles['courts']=$courts;
		if ($this->input->post("isAjax")) {
			header('content-type:application:json;charset=utf8');
			header('Access-Control-Allow-Origin:*');
			header('Access-Control-Allow-Methods:POST');
			header('Access-Control-Allow-Headers:x-requested-with,content-type');
			$result = array();
			$result['isSuccess'] = true;
			$result['errorMessage'] = '';
			$result['data'] = $sdlist;
			echo json_encode($result, JSON_UNESCAPED_UNICODE);
		} else {
			$this->load->view('head_sec', $articles);
			$this->load->view('sd_announce_list', $articles);
			$this->load->view('foot_sec', $articles);
		}
	}
//	提供给ajax方法调用
	public function ajax_sd_list($p=1,$cbfy='')
	{
		print_r($cbfy);
		$data=array();
		$data['pageno'] = $p;
		$data['pagesize'] = 10;
		$data['cbfy'] = $cbfy;
		$url='http://www.zjsfgkw.cn/Notice/NoticeSD';
		$timeout = 40;
		$response=$this->httppost->post($url,$data,$timeout);
		$sdlist=json_decode($response);

		//print_r($sdlist[1]['total']);

		$articles=array('t=itle'=>'送达公告');
		$articles['court_announces']=$sdlist;
		$this->load->view('head_sec',$articles);
		$this->load->view('sd_announce_list',$articles);
		$this->load->view('foot_sec',$articles);
	}
	public function detail($id){
		$article=$this->Article_Model->get_article_by_id($id);
		$title=$article['title'];
		$content=$article['content'];
		$data=array('title'=>$title,
			'content'=>$content
		);
		$this->load->view('head_sec',$data);
		$this->load->view('article_detail',$data);
		$this->load->view('foot_sec',$data);
	}
}


